import {
  Body,
  Controller,
  Delete,
  Get,
  Param,
  Post,
  Put,
  Query,
  Req,
  Res,
  Session,
} from '@nestjs/common';
import { UserService } from './user.service';
import { UserItem } from 'src/core/types/user';

@Controller('/user')
export class UserController {
  constructor(private readonly userService: UserService) {}

  @Get()
  async index(@Req() req, @Res() res) {
    return this.userService.index(req, res);
  }

  @Get('/captcha')
  createCode(@Req() req, @Res() res, @Session() session) {
    return this.userService.createCode(req, res, session);
  }

  @Get('/getUserList')
  getUserList(): UserItem[] {
    return this.userService.getUserList();
  }

  @Post('addUser')
  addUser(@Body() userData): UserItem[] {
    return this.userService.addUser(userData);
  }

  @Get('getUserDetail/:id')
  getUserDetail(@Param('id') id: string): UserItem {
    return this.userService.getUserDetail(id);
  }

  @Put('updateUser')
  updateUser(@Body() userData): UserItem[] {
    return this.userService.updateUser(userData);
  }

  @Delete('deleteUser')
  deleteUser(@Query() query): UserItem[] {
    return this.userService.deleteUser(query.id);
  }
}
